package com.gjm.product.controller;

import com.gjm.product.dao.objectdata.ProductInfo;
import com.gjm.product.service.ProductService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/product")
@RestController
public class ProductController {

    @Resource(name = "productServiceImpl")
    private ProductService productService;

    @RequestMapping("/getProductInfoById")
    public ProductInfo getProductInfoById(Integer productId) {
        return productService.getProductInfoById(productId);
    }

    @RequestMapping("/method1")
    public String method1(@RequestParam("id") Integer id) {
        return "product-service 接收到 id: " + id;
    }

    @RequestMapping("/method2")
    public String method2(@RequestParam("id") Integer id,
                          @RequestParam("name") String name) {

        return "product-service 接收到 id: " + id + ", name: " + name;
    }

    @RequestMapping("/method3")
    public String method3(ProductInfo productInfo) {
        return productInfo.toString();
    }

    @RequestMapping("/method4")
    public String method4(@RequestBody ProductInfo productInfo) {
        return productInfo.toString();
    }
}
